package com.mbatis.produerConsumer;

import java.util.concurrent.Semaphore;

/**
 * 信号量 Semaphore 实现生产者消费者
 */
public class PCTest4 {

    private static  Integer count = 0;
    //创建三个信号量
    final  Semaphore full = new Semaphore(10);
    final  Semaphore empty = new Semaphore(0);
    final  Semaphore mutex = new Semaphore(1);

    public static void main(String[] args) {


    }

    class Producer implements Runnable{

        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }


            }
        }
    }


    class Consumer implements Runnable{

        @Override
        public void run() {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
